﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="AddDocument.Script"
   Location ="ScriptLink"
                Rights="ManageWeb"
    ScriptBlock="function OpenAddDialog() {
            var ctx = SP.ClientContext.get_current();
            var items = SP.ListOperation.Selection.getSelectedItems(ctx);
            var myItems = '';
            var k;

            for (k in items)
            {
              myItems += ';' + items[k].id;
            }

            var options = SP.UI.$create_DialogOptions();
            options.url = '~site/_layouts/stc/ApplicationPages/ListItemPermission.aspx?itemIds='+myItems+ '&amp;list=' + SP.ListOperation.Selection.getSelectedList();
            options.title = 'Set Item Permissions'
            //options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
            SP.UI.ModalDialog.showModalDialog(options);
            }

            function enableDisableButton() { 
                return CountDictionary(SP.ListOperation.Selection.getSelectedItems()) > 0; 
             }"/>
  <CustomAction Id="SetPermission" RegistrationType="List"
  RegistrationId="100" Location="CommandUI.Ribbon.ListView">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListItem.Actions.Controls._children">
          <Button Id="Ribbon.Documents.New.Controls.AddDocument"
          Alt="Set Permissions " Sequence="10"
          Image16by16="/_layouts/stc/images/setPermission16.png"
          Image32by32="/_layouts/stc/images/setPermission32.png"
          Command="SetPermission" LabelText="Set Permissions"
          TemplateAlias="o2" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="SetPermission"
        EnabledScript="javascript:enableDisableButton();"
        CommandAction="javascript:OpenAddDialog();" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

<!--<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="ShowHelloWorldButton"
    RegistrationType="List"
    RegistrationId="100"
    Location="CommandUI.Ribbon.ListView"
    ScriptSrc="/_Layouts/stc/JS/stcItemLevelPermission.js"
    Rights="EditListItems">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.ListItem.Manage.Controls._children">
          <Button
           Id="ShowHelloWorldButton"
           Alt="Show HelloWorld Alert"
           Sequence="1"
           Image32by32="/_layouts/DemoSharePointRibbon/HelloWorld.jpg"
           Command="ShowHelloWorldCommand"
           LabelText="Hello World"
           TemplateAlias="o1"
           CommandType="General"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="ShowHelloWorldCommand"
         EnabledScript="javascript:EnableButton();"
         CommandAction="javascript:GetSelectedItemsId();" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
  <CustomAction
    Id="ShowHelloWorldCommand.Script"
    Location="ScriptLink"
    ScriptSrc ="/_layouts/stc/js/stcItemLevelPermission.js"/>
</Elements>-->